<div class="hoverCart" onclick="location.href='/home/order/cart'">
    <a>0</a>
</div>
<script src="/js/jquery.cookie.js"></script>
<script>
    var cartGoods = {};
    var storageKey = 'cart_goods';

    // 加入购物车
    function addCart(obj, goodsId) {
        var shopOffset = $(".hoverCart").offset();
        var cloneDiv = $(obj).parent().siblings(".goodsPic").clone();
        var proOffset = $(obj).parent().siblings(".goodsPic").offset();
        cloneDiv.css({ "position": "absolute", "top": proOffset.top, "left": proOffset.left });
        $(obj).parent().siblings(".goodsPic").parent().append(cloneDiv);
        cloneDiv.animate({
            width:0,
            height:0,
            left: shopOffset.left,
            top: shopOffset.top,
            opacity:1
        },"slow");

        if (cartGoods[goodsId]) {
            cartGoods[goodsId] = cartGoods[goodsId] + 1;
        } else {
            cartGoods[goodsId] = 1;
        }
        $('.hoverCart a').text(Object.keys(cartGoods).length);
        $.cookie(storageKey, JSON.stringify(cartGoods), {expires: 1, path: '/'});
    }

    $(function () {
        cartGoods = $.cookie(storageKey) ? JSON.parse($.cookie(storageKey)) : {};

        // 购物车数量
        $('.hoverCart a').text(Object.keys(cartGoods).length);
    });
</script>